using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace BabyCloudDrives.DesktopApp.Models.Converter
{
    public class SkyDriveSharedTypeConvert : StringEnumConverter
    {
        public override bool CanConvert(Type objectType)
        {
            return objectType == typeof (SkyDriveSharedType);
        }

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
                                        JsonSerializer serializer)
        {
            switch (reader.Value.ToString())
            {
                case "Just me":
                    return SkyDriveSharedType.JustMe;
                case "Everyone (public)":
                    return SkyDriveSharedType.Everyone;
                case "People I selected":
                    return SkyDriveSharedType.PeopleISelected;
                case "Friends":
                    return SkyDriveSharedType.Friends;
                case "My friends and their friends":
                    return SkyDriveSharedType.MyFriendsAndTheirFriends;
                case "People with a link":
                    return SkyDriveSharedType.PeopleWithALink;
                default:
                    return SkyDriveSharedType.Unknown;
            }
        }

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            SkyDriveSharedType skyDriveShared = (SkyDriveSharedType) value;
            switch (skyDriveShared)
            {
                case SkyDriveSharedType.JustMe:
                    writer.WriteValue("Just me");
                    break;
                case SkyDriveSharedType.Everyone:
                    writer.WriteValue("Everyone (public)");
                    break;
                case SkyDriveSharedType.PeopleISelected:
                    writer.WriteValue("People I selected");
                    break;
                case SkyDriveSharedType.Friends:
                    writer.WriteValue("Friends");
                    break;
                case SkyDriveSharedType.MyFriendsAndTheirFriends:
                    writer.WriteValue("My friends and their friends");
                    break;
                case SkyDriveSharedType.PeopleWithALink:
                    writer.WriteValue("People with a link");
                    break;
                default:
                    writer.WriteValue("Unknown");
                    break;
            }
        }
    }
}